package com.example.main.controller;

import com.baomidou.kaptcha.Kaptcha;
import com.example.common.utils.R;
import com.example.main.controller.vo.UserVO;
import com.example.main.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @NAME: WSC
 * @DATE: 2021/12/14
 * @DESCRIBE:
 **/
@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    UserService userService;
    @Autowired
    private Kaptcha kaptcha;

    @PostMapping("/login")
    public R login(@RequestBody UserVO userVO) {
        /**
         * 验证码
         */
        kaptcha.validate(userVO.getCode());

        boolean ret = userService.login(userVO);

        if (ret) {
            return R.ok();
        }

        return R.error("账号或者密码错误");
    }
}
